// pages/myCollect/myCollect.js
const {
  deleteFav,
  favList
} = require('../../utils/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [],
    haveCollect: false
  },
  toClassify() {
    wx.reLaunch({
      url: '/pages/classify/classify'
    });
  },
  deleteFav(e) {
    const info = e.currentTarget.dataset.operation
    var token = wx.getStorageSync('token')
    const queryInfo = {}
    queryInfo.goodsId = info.goodsId
    queryInfo.token = token
    console.log(queryInfo)

    deleteFav(queryInfo).then(res => {
      console.log(res)
    })
    this.getCollectList()
  },
  toGoodsDetail(e) {
    const id = e.currentTarget.dataset.operation
    console.log(id)
    // url="/pages/goodsDetail/goodsDetail?id={{item.id}}"
    wx.navigateTo({
      url: `/pages/goodsDetail/goodsDetail?id=${id}`
    })
  },
  getCollectList(){
    const that = this
    var token = wx.getStorageSync('token')
    favList({ token: token }).then(res => {
      console.log(res)
      if (res.code == 700) {
        that.setData({
          haveCollect:false,
          goodsList: res.data
        })
      } else {
        that.setData({
          haveCollect:true,
          goodsList: res.data
        })
      }
      console.log(that.data.haveCollect)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCollectList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})